package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListGoodsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 报溢单
 */
@RestController
@RequestMapping("/overflowListGoods")
public class OverflowListGoodsController {
    @Autowired
    private OverflowListGoodsService overflowListGoodsService;
    @Autowired
    private UserController userController;
    /**
     *
     */
    /**
     * 保存报溢单
     */
    @PostMapping("/save")
    public ServiceVO save(@RequestParam("overflowNumber") String overflowNumber,
                          @RequestParam("overflowDate") String overflowDate,
                          @RequestParam("remarks") String remarks,
                          @RequestParam("overflowListGoodsStr") String overflowListGoodsStr,
                          HttpSession session){
        Map<String,Object> map = userController.loadUserInfo(session);
        List<String> list = new ArrayList<>();
        for (String key : map.keySet()) {
            list.add((String) map.get(key));
        }
        Integer userID = userController.getUserId(list);
        overflowListGoodsService.save(overflowNumber,overflowDate,remarks,overflowListGoodsStr,userID);
        ServiceVO serviceVO = new ServiceVO(100,"请求成功",null);
        return serviceVO;
    }

    /**
     * 报溢单查询
     */
    @PostMapping("/list")
    public Map<String,Object> list(@Param("sTime") String sTime,
                                   @Param("eTime") String eTime){
        List<OverflowList> list = overflowListGoodsService.list(sTime,eTime);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }
    /**
     * 报溢单商品信息
     */
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(@RequestParam("overflowListId") Integer overflowListId){
        List<OverflowListGoods> list = overflowListGoodsService.goodsList(overflowListId);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",list);

        return map;


    }
}
